var gl_vue_vm_list_asset_html = $('#vue_vm_list_asset').html();

$(function() {
	$('#vue_vm_list div').hide();
	$('#vue_vm_list_asset div').hide();
});

var roomAsset = {
	roomAssetId: '',
	buildingId: '',
	buildingName: '',
	floorsId: '',
	floorsName: '',
	roomId: '',
	roomNumber: '',
	assetName: '',
	quantity: '',
	createTime: '',
	updateTime: '',
	createId: getLoginedUser()? getLoginedUser().staffId: '',
	updateId: getLoginedUser()? getLoginedUser().staffId: '',
	assetId: '',
};

findAllAsset();

function findAllAsset() {
	if($('#vue_vm_list').length==0) {return;}
	$('#vue_vm_list div').hide();

	findAll_basic(path+'/asset/findAll', function(response) {
		$('#vue_vm_list').html(gl_vue_vm_list_html);
		
		new Vue({
			el: '#vue_vm_list',
			data: {
				todos: response.data
			},
			methods: {
				roomAsset_save:function(todo) {
					todo.buildingId = $('#building_select').val();
					todo.buildingName = $('#building_select option:selected').text();
					todo.floorsId = $('#floor_select').val();
					todo.floorsName = $('#floor_select option:selected').text();
					todo.roomId = selectedRoom.roomId;
					todo.roomNumber = selectedRoom.roomNumber;
					todo.roomType = selectedRoom.roomType;
					todo.quantity = parseInt($('#'+todo.assetId+'_quantity').val());
					
					save_basic(path+'/roomAsset/save', {roomAsset:todo}, function() {
						alert('添加成功');
					});
				}
			}
		});
		
		$('#vue_vm_list div').show();
	});
}

load_roomAsset_by_roomId = function(roomId) {
	$('#vue_vm_list_asset div').hide();
	$('#roomNumber').text('');
	$('#roomType').text('');
	
	if(!roomId || roomId=='') {return;}

	find_basic_by_json(path+'/roomAsset/findByRoomId', {roomId: roomId}, function(response) {
		$('#vue_vm_list_asset').html(gl_vue_vm_list_asset_html);
		
		new Vue({
			el: '#vue_vm_list_asset',
			data: {
				todos: response.data
			}
		});
		
		$('#vue_vm_list_asset div').show();
		$('#roomNumber').text(selectedRoom.roomNumber);
		$('#roomType').text(selectedRoom.roomType);
	});
}

function deleteBatch() {
	deleteBatch_basic(path+'/roomAsset/deleteBatch');
}
